from typing import List


class Solution:
    def missingElement(self, nums: List[int], k: int) -> int:
        size = len(nums)
        if size == 1:
            return nums[0] + k

        left, right = 0, size
        while left < right:
            mid = (left + right) // 2
            if nums[mid] < nums[0] + mid + k:
                left = mid + 1
            else:
                right = mid
        return nums[0] + left + k - 1


if __name__ == "__main__":
    print(Solution().missingElement(nums=[4, 7, 9, 10], k=1))  # 5
    print(Solution().missingElement(nums=[4, 7, 9, 10], k=3))  # 8
    print(Solution().missingElement(nums=[1, 2, 4], k=3))  # 6
